<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ NameServer 核心机制解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
        }
        .code-block {
            background-color: #1e293b;
            color: #e2e8f0;
            border-radius: 0.5rem;
            padding: 1.5rem;
            overflow-x: auto;
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .nav-link::after {
            content: '';
            display: block;
            width: 0;
            height: 2px;
            background: #3b82f6;
            transition: width .3s;
        }
        .nav-link:hover::after {
            width: 100%;
        }
        .highlight {
            position: relative;
        }
        .highlight::before {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(59, 130, 246, 0.2);
            z-index: -1;
            transition: height 0.3s ease;
        }
        .highlight:hover::before {
            height: 50%;
        }
    </style>
</head>
<body class="antialiased">
    <!-- 导航栏 -->
    <nav class="bg-white shadow-sm sticky top-0 z-50">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16">
                <div class="flex items-center">
                    <div class="flex-shrink-0 flex items-center">
                        <i class="fas fa-rocket text-blue-500 text-2xl mr-2"></i>
                        <span class="text-xl font-bold text-gray-900">RocketMQ 技术解析</span>
                    </div>
                </div>
                <div class="hidden md:ml-6 md:flex md:items-center md:space-x-8">
                    <a href="#core-functions" class="nav-link text-gray-700 hover:text-blue-600 px-3 py-2 text-sm font-medium">核心功能</a>
                    <a href="#implementation" class="nav-link text-gray-700 hover:text-blue-600 px-3 py-2 text-sm font-medium">实现机制</a>
                    <a href="#high-availability" class="nav-link text-gray-700 hover:text-blue-600 px-3 py-2 text-sm font-medium">高可用设计</a>
                    <a href="#best-practices" class="nav-link text-gray-700 hover:text-blue-600 px-3 py-2 text-sm font-medium">最佳实践</a>
                </div>
            </div>
        </div>
    </nav>

    <!-- Hero 区域 -->
    <div class="hero-gradient text-white">
        <div class="max-w-7xl mx-auto py-24 px-4 sm:py-32 sm:px-6 lg:px-8">
            <div class="text-center">
                <h1 class="text-4xl font-extrabold tracking-tight sm:text-5xl lg:text-6xl mb-6">
                    <span class="highlight inline-block">RocketMQ NameServer</span>
                </h1>
                <p class="max-w-3xl mx-auto text-xl opacity-90">
                    分布式消息系统的服务注册与发现核心机制解析
                </p>
                <div class="mt-10 flex justify-center space-x-4">
                    <a href="#core-functions" class="inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md text-blue-700 bg-white hover:bg-gray-50">
                        <i class="fas fa-book-open mr-2"></i> 核心功能
                    </a>
                    <a href="#implementation" class="inline-flex items-center px-6 py-3 border border-white text-base font-medium rounded-md text-white hover:bg-blue-700">
                        <i class="fas fa-code mr-2"></i> 实现机制
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- 核心功能部分 -->
        <section id="core-functions" class="mb-20">
            <div class="text-center mb-16">
                <h2 class="text-3xl font-bold text-gray-900 mb-4">
                    <span class="highlight inline-block">NameServer的核心功能</span>
                </h2>
                <p class="max-w-3xl mx-auto text-gray-600">
                    NameServer是RocketMQ的核心组件之一，它充当着服务注册中心的角色，负责管理Broker的注册信息并提供路由发现服务。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-route text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">路由注册与管理</h3>
                        </div>
                        <p class="mt-2 text-gray-600">
                            NameServer管理集群中所有Broker的路由信息，包括Broker注册信息、Topic路由信息和Broker存活状态。
                        </p>
                        <div class="mt-6">
                            <div class="code-block">
                                <pre><code class="text-sm">// NameServer中的路由信息表结构
public class RouteInfoManager {
    // Topic与队列信息的映射
    private final HashMap&lt;String, List&lt;QueueData&gt;&gt; topicQueueTable;
    
    // Broker名称与Broker数据的映射
    private final HashMap&lt;String, BrokerData&gt; brokerAddrTable;
    
    // Broker地址与集群名称的映射
    private final HashMap&lt;String, Set&lt;String&gt;&gt; clusterAddrTable;
    
    // Broker地址与上次更新时间的映射
    private final HashMap&lt;String, BrokerLiveInfo&gt; brokerLiveTable;
    
    // Broker地址与过滤服务器地址列表的映射
    private final HashMap&lt;String, List&lt;String&gt;&gt; filterServerTable;
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-search text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">路由发现服务</h3>
                        </div>
                        <p class="mt-2 text-gray-600">
                            NameServer为客户端（Producer和Consumer）提供路由发现服务，使它们能够找到对应Topic的消息队列所在的Broker。
                        </p>
                        <div class="mt-6">
                            <div class="mermaid">
                                sequenceDiagram
                                    participant Producer
                                    participant NameServer
                                    Producer->>NameServer: 路由查询请求(Topic名称)
                                    NameServer->>NameServer: 查询内存中的路由表
                                    NameServer-->>Producer: 返回路由信息
                                    Note right of Producer: 客户端缓存路由信息<br>并定期更新
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-server text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">无状态设计</h3>
                        </div>
                        <p class="mt-2 text-gray-600">
                            NameServer采用无状态设计，所有路由信息都存储在内存中，不依赖外部存储系统，通过心跳超时机制自动清理不可用的Broker。
                        </p>
                        <div class="mt-4">
                            <div class="flex items-center text-sm text-gray-500">
                                <i class="fas fa-check-circle text-green-500 mr-2"></i>
                                简单高效，减少了系统复杂度
                            </div>
                            <div class="flex items-center text-sm text-gray-500 mt-2">
                                <i class="fas fa-check-circle text-green-500 mr-2"></i>
                                高可用性和可靠性
                            </div>
                            <div class="flex items-center text-sm text-gray-500 mt-2">
                                <i class="fas fa-check-circle text-green-500 mr-2"></i>
                                重启后依靠Broker心跳重新构建路由表
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-heartbeat text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">心跳机制</h3>
                        </div>
                        <p class="mt-2 text-gray-600">
                            NameServer通过心跳机制监控Broker的健康状态，Broker每30秒发送一次心跳，NameServer每10秒检查一次Broker状态。
                        </p>
                        <div class="mt-6">
                            <div class="code-block">
                                <pre><code class="text-sm">// NameServer中的心跳检测代码
public void scanNotActiveBroker() {
    Iterator&lt;Entry&lt;String, BrokerLiveInfo&gt;&gt; it = 
        this.brokerLiveTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry&lt;String, BrokerLiveInfo&gt; entry = it.next();
        long lastUpdateTimestamp = entry.getValue()
            .getLastUpdateTimestamp();
        if ((System.currentTimeMillis() - lastUpdateTimestamp) > 
            BROKER_CHANNEL_EXPIRED_TIME) {
            // 超过120秒未收到心跳，移除Broker
            it.remove();
            // 清理相关路由信息
            this.onBrokerInactive(entry.getKey());
        }
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 实现机制部分 -->
        <section id="implementation" class="mb-20">
            <div class="text-center mb-16">
                <h2 class="text-3xl font-bold text-gray-900 mb-4">
                    <span class="highlight inline-block">服务注册与发现的实现机制</span>
                </h2>
                <p class="max-w-3xl mx-auto text-gray-600">
                    NameServer通过精心设计的注册与发现机制，确保分布式消息系统的稳定运行。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-sign-in-alt text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">Broker注册流程</h3>
                        </div>
                        <p class="mt-2 text-gray-600">
                            Broker在启动时会向所有配置的NameServer注册自己，并定期发送心跳保持连接。
                        </p>
                        <div class="mt-6">
                            <div class="code-block">
                                <pre><code class="text-sm">// Broker向NameServer注册的代码
public void registerBrokerAll(boolean checkOrderConfig, 
    boolean oneway, boolean forceRegister) {
    // 构建注册请求
    TopicConfigSerializeWrapper topicConfigWrapper = 
        this.topicConfigManager.buildTopicConfigSerializeWrapper();
    
    // 注册到所有NameServer
    List&lt;String&gt; nameServerAddressList = 
        this.namesrvController.getNameServerAddressList();
    if (nameServerAddressList != null && nameServerAddressList.size() > 0) {
        for (String namesrvAddr : nameServerAddressList) {
            try {
                this.registerBroker(namesrvAddr, oneway, 
                    forceRegister, topicConfigWrapper);
            } catch (Exception e) {
                // 处理异常
            }
        }
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-search-location text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">客户端发现服务流程</h3>
                        </div>
                        <p class="mt-2 text-gray-600">
                            Producer和Consumer通过NameServer获取路由信息，确定消息发送或消费的目标Broker。
                        </p>
                        <div class="mt-6">
                            <div class="mermaid">
                                graph TD
                                    A[客户端启动] --> B[随机选择NameServer]
                                    B --> C{连接成功?}
                                    C -->|是| D[获取路由信息]
                                    C -->|否| E[尝试下一个NameServer]
                                    D --> F[缓存路由信息]
                                    F --> G[定期更新]
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300 mb-12">
                <div class="p-6">
                    <div class="flex items-center mb-4">
                        <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                            <i class="fas fa-sync-alt text-xl"></i>
                        </div>
                        <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">路由信息更新机制</h3>
                    </div>
                    <div class="mt-4 grid md:grid-cols-2 gap-6">
                        <div>
                            <h4 class="font-medium text-gray-800 mb-2">Broker端更新</h4>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>定期心跳：每30秒发送一次心跳，包含最新的Topic配置</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>Topic变更：当Broker上的Topic配置发生变化时，立即更新</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>Broker重启：重启后重新向所有NameServer注册</span>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800 mb-2">NameServer端更新</h4>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>收到Broker注册请求或心跳包后更新内存中的路由表</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>每10秒扫描一次brokerLiveTable，清理失效Broker</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 高可用设计部分 -->
        <section id="high-availability" class="mb-20">
            <div class="text-center mb-16">
                <h2 class="text-3xl font-bold text-gray-900 mb-4">
                    <span class="highlight inline-block">NameServer的高可用设计</span>
                </h2>
                <p class="max-w-3xl mx-auto text-gray-600">
                    NameServer采用了简单而有效的高可用设计，确保分布式消息系统的稳定运行。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-project-diagram text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">无状态设计</h3>
                        </div>
                        <div class="mt-4 space-y-3 text-gray-600">
                            <p class="flex items-start">
                                <i class="fas fa-check text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>所有NameServer实例是对等的，没有主从关系</span>
                            </p>
                            <p class="flex items-start">
                                <i class="fas fa-check text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>NameServer之间不需要数据同步，每个实例独立工作</span>
                            </p>
                            <p class="flex items-start">
                                <i class="fas fa-check text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>所有数据都存储在内存中，重启后通过Broker心跳重建</span>
                            </p>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-network-wired text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">多实例部署</h3>
                        </div>
                        <div class="mt-4">
                            <div class="mermaid">
                                graph LR
                                    A[Broker] --> B[NameServer1]
                                    A --> C[NameServer2]
                                    A --> D[NameServer3]
                                    E[Producer] --> C
                                    F[Consumer] --> B
                            </div>
                            <div class="mt-4 text-sm text-gray-600">
                                <p class="flex items-start">
                                    <i class="fas fa-cog text-blue-500 mt-1 mr-2"></i>
                                    <span>配置示例:<br><code class="bg-gray-100 px-2 py-1 rounded">namesrvAddr=192.168.1.1:9876;192.168.1.2:9876;192.168.1.3:9876</code></span>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-exchange-alt text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">故障转移机制</h3>
                        </div>
                        <div class="mt-4 space-y-3 text-gray-600">
                            <p class="flex items-start">
                                <i class="fas fa-random text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>客户端随机选择一个NameServer进行连接，失败时尝试下一个</span>
                            </p>
                            <p class="flex items-start">
                                <i class="fas fa-heartbeat text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>Broker向所有NameServer注册，即使部分NameServer故障也不影响</span>
                            </p>
                            <p class="flex items-start">
                                <i class="fas fa-clock text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>客户端定期从NameServer获取路由信息，保证及时更新</span>
                            </p>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-bolt text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">轻量级设计</h3>
                        </div>
                        <div class="mt-4 space-y-3 text-gray-600">
                            <p class="flex items-start">
                                <i class="fas fa-tachometer-alt text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>没有复杂的集群管理和状态同步机制</span>
                            </p>
                            <p class="flex items-start">
                                <i class="fas fa-memory text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>内存存储，CPU和IO消耗较低</span>
                            </p>
                            <p class="flex items-start">
                                <i class="fas fa-rocket text-blue-500 mt-1 mr-2 text-sm"></i>
                                <span>启动迅速，故障恢复时间短</span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 最佳实践部分 -->
        <section id="best-practices" class="mb-20">
            <div class="text-center mb-16">
                <h2 class="text-3xl font-bold text-gray-900 mb-4">
                    <span class="highlight inline-block">实际应用中的最佳实践</span>
                </h2>
                <p class="max-w-3xl mx-auto text-gray-600">
                    合理配置和优化NameServer，确保其在生产环境中的高性能和高可用性。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-server text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">部署建议</h3>
                        </div>
                        <div class="mt-4">
                            <h4 class="font-medium text-gray-800 mb-2">实例数量</h4>
                            <ul class="space-y-2 text-gray-600 mb-4">
                                <li class="flex items-start">
                                    <span class="bg-blue-100 text-blue-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded">最小</span>
                                    <span>建议至少部署2个NameServer实例</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="bg-blue-100 text-blue-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded">推荐</span>
                                    <span>生产环境建议部署3-5个NameServer实例</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="bg-blue-100 text-blue-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded">大型</span>
                                    <span>大型集群可部署更多，但通常不超过10个</span>
                                </li>
                            </ul>
                            <h4 class="font-medium text-gray-800 mb-2">部署位置</h4>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-desktop text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>跨机器部署：NameServer实例应该部署在不同的物理机上</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-vector-square text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>跨机架部署：在条件允许的情况下，建议跨机架部署</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-globe-americas text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>跨数据中心：每个数据中心都应该有NameServer实例</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-sliders-h text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">配置优化</h3>
                        </div>
                        <div class="mt-4">
                            <h4 class="font-medium text-gray-800 mb-2">JVM配置</h4>
                            <div class="code-block mb-4">
                                <pre><code class="text-sm"># NameServer的JVM配置示例
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g"
JAVA_OPT="${JAVA_OPT} -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC"
JAVA_OPT="${JAVA_OPT} -XX:+UseCMSCompactAtFullCollection"
JAVA_OPT="${JAVA_OPT} -XX:CMSInitiatingOccupancyFraction=70"
JAVA_OPT="${JAVA_OPT} -XX:+CMSParallelRemarkEnabled"
JAVA_OPT="${JAVA_OPT} -XX:+PrintGCDetails"
JAVA_OPT="${JAVA_OPT} -XX:+PrintGCDateStamps"
JAVA_OPT="${JAVA_OPT} -Xloggc:/dev/shm/rmq_srv_gc.log"</code></pre>
                            </div>
                            <h4 class="font-medium text-gray-800 mb-2">系统参数</h4>
                            <div class="code-block">
                                <pre><code class="text-sm"># NameServer配置文件示例
listenPort=9876
kvConfigPath=/home/rocketmq/namesrv/kvConfig.json
configStorePath=/home/rocketmq/namesrv/namesrv.properties
orderMessageEnable=false</code></pre>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-chart-line text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">监控与运维</h3>
                        </div>
                        <div class="mt-4">
                            <h4 class="font-medium text-gray-800 mb-2">关键监控指标</h4>
                            <ul class="space-y-2 text-gray-600 mb-4">
                                <li class="flex items-start">
                                    <i class="fas fa-heart text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>NameServer存活状态</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-memory text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>JVM指标：内存使用率、GC频率和时间</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-tachometer-alt text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>系统资源：CPU使用率、内存使用率、网络流量</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-stopwatch text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>请求处理：请求处理时间、请求成功率</span>
                                </li>
                            </ul>
                            <h4 class="font-medium text-gray-800 mb-2">常见问题处理</h4>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <div class="bg-red-100 text-red-800 text-xs font-medium mr-2 px-2 py-0.5 rounded flex-shrink-0">问题</div>
                                    <span>NameServer无法启动</span>
                                </li>
                                <li class="flex items-start">
                                    <div class="bg-yellow-100 text-yellow-800 text-xs font-medium mr-2 px-2 py-0.5 rounded flex-shrink-0">处理</div>
                                    <span>检查端口是否被占用，JVM配置是否合适，日志中的错误信息</span>
                                </li>
                                <li class="flex items-start">
                                    <div class="bg-red-100 text-red-800 text-xs font-medium mr-2 px-2 py-0.5 rounded flex-shrink-0">问题</div>
                                    <span>客户端连接失败</span>
                                </li>
                                <li class="flex items-start">
                                    <div class="bg-yellow-100 text-yellow-800 text-xs font-medium mr-2 px-2 py-0.5 rounded flex-shrink-0">处理</div>
                                    <span>检查网络连接，NameServer地址配置，防火墙设置</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden feature-card transition-all duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600">
                                <i class="fas fa-expand-arrows-alt text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg leading-6 font-medium text-gray-900">扩展与优化</h3>
                        </div>
                        <div class="mt-4">
                            <h4 class="font-medium text-gray-800 mb-2">动态扩容</h4>
                            <ol class="list-decimal pl-5 space-y-2 text-gray-600 mb-4">
                                <li>部署新的NameServer实例</li>
                                <li>更新客户端和Broker的NameServer地址列表</li>
                                <li>重启客户端和Broker，或者等待它们自动更新配置</li>
                            </ol>
                            <h4 class="font-medium text-gray-800 mb-2">性能优化</h4>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-memory text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>增加内存：NameServer主要使用内存存储路由信息</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-network-wired text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>优化网络：确保NameServer与客户端、Broker之间的网络连接良好</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-cog text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>调整JVM参数：根据实际情况优化GC性能</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- 页脚 -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="text-xl font-bold mb-2">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition-colors">
                    <i class="fas fa-link mr-1"></i> http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>